﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Web.UI;
using System.ComponentModel;

namespace Axe.Windows.Forms
{
    public class HardcodedComboBox<TObj,TKey,TValue> : ComboBox
    {
        IEnumerable<TObj> m_Objects = null;

        public HardcodedComboBox()
        {
            base.DropDownStyle = ComboBoxStyle.DropDownList;
        }

        #region public new ComboBoxStyle DropDownStyle
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new ComboBoxStyle DropDownStyle
        {
            get { return ComboBoxStyle.DropDownList; }
        } 
        #endregion

        #region public new IEnumerable<TObj> DataSource
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new IEnumerable<TObj> DataSource
        {
            get
            {
                return base.DataSource as IEnumerable<TObj>;
            }
            set
            {
                Items.Clear();
                m_Objects = value;
                if (value != null)
                {
                    foreach (TObj o in value)
                    {
                        Items.Add(o);
                    }
                }
            }
        } 
        #endregion

        public new TObj SelectedItem
        {
            get
            {
                return (TObj)base.SelectedItem;
            }
            set
            {
                base.SelectedItem = value;
            }
        }

        #region public TKey SelectedValue
        public new TKey SelectedValue
        {
            get
            {
                if (this.SelectedItem == null)
                    return default(TKey);

                return (TKey)DataBinder.GetPropertyValue(SelectedItem, ValueMember);
            }
        } 
        #endregion

        #region public TValue SelectedName
        public TValue SelectedName
        {
            get
            {
                if (this.SelectedItem == null)
                    return default(TValue);

                return (TValue)DataBinder.GetPropertyValue(SelectedItem, DisplayMember);
            }
        } 
        #endregion

        public void DataBind()
        {

        }
    }
}
